<?php 
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Product_model extends MY_Model
{
	public $soft_delete = FALSE;

	public $_table = TABLE_PRODUCT;

	public $primary_key = 'id';

	public $return_type = 'array';

	public $select_field = 'id,sort,title,hit,createtime,content';
	
	public function ajax_sort()
	{
	    $query=$this->db->order_by("sort", "asc")
	                    ->get(TABLE_PRODUCT);
	    $query->result_array();             
	    return ($query->num_rows()>0) ? TRUE : FALSE ;
	}
	
    //公告排序更新
    public function sort_updata($new_array)
    {
	     foreach($new_array as $val)
	     {
	        $nSort=array('sort'=>$val['sort']);
	        $nid =$val['id'];
	        $this->db->where('id',$nid);
	        $data=$this->db->update($this->_table,$nSort);
	     }
    }
    
    //删除产品列表内容
    public function del_product($val)
    {
        $sql="delete from ".$this->db->dbprefix.TABLE_PRODUCT." where id in ($val)";
        $this->db->query($sql);
        return ($this->db->affected_rows()>0)?true:false;
    }
    //删除单个产品
    public function delSingle($id)
    {
        $sql="delete from ".$this->db->dbprefix.TABLE_PRODUCT." where id =\"$id\"";
        $this->db->query($sql);
        return ($this->db->affected_rows()>0)?true:false;
    }
}